package com.ruoyi.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.BusPipeNetwork;
import com.ruoyi.business.service.IBusPipeNetworkService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 管网台账Controller
 * 
 * @author wf
 * @date 2024-07-18
 */
@RestController
@RequestMapping("/business/network")
public class BusPipeNetworkController extends BaseController
{
    @Autowired
    private IBusPipeNetworkService busPipeNetworkService;
    @Value("${export.max:10000}")
    private Integer max;

    /**
     * 查询管网台账列表
     */
    @PreAuthorize("@ss.hasPermi('business:network:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusPipeNetwork busPipeNetwork)
    {
        startPage();
        List<BusPipeNetwork> list = busPipeNetworkService.selectBusPipeNetworkList(busPipeNetwork);
        return getDataTable(list);
    }

    /**
     * 导出管网台账列表
     */
    @PreAuthorize("@ss.hasPermi('business:network:export')")
    @Log(title = "管网台账", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusPipeNetwork busPipeNetwork)
    {
        List<BusPipeNetwork> list = busPipeNetworkService.selectBusPipeNetworkList(busPipeNetwork);
        if (list.size() > max) {
            throw new ServiceException("导出失败！,每次最多导出 " + max + "条");
        }
        ExcelUtil<BusPipeNetwork> util = new ExcelUtil<BusPipeNetwork>(BusPipeNetwork.class);
        util.exportExcel(response, list, "管网台账数据");
    }

    /**
     * 获取管网台账详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:network:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(busPipeNetworkService.selectBusPipeNetworkById(id));
    }

    /**
     * 新增管网台账
     */
    @PreAuthorize("@ss.hasPermi('business:network:add')")
    @Log(title = "管网台账", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusPipeNetwork busPipeNetwork)
    {
        return toAjax(busPipeNetworkService.insertBusPipeNetwork(busPipeNetwork));
    }

    /**
     * 修改管网台账
     */
    @PreAuthorize("@ss.hasPermi('business:network:edit')")
    @Log(title = "管网台账", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusPipeNetwork busPipeNetwork)
    {
        return toAjax(busPipeNetworkService.updateBusPipeNetwork(busPipeNetwork));
    }

    /**
     * 删除管网台账
     */
    @PreAuthorize("@ss.hasPermi('business:network:remove')")
    @Log(title = "管网台账", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(busPipeNetworkService.deleteBusPipeNetworkByIds(ids));
    }
}
